﻿#ifndef UTILS_H
#define UTILS_H

#include"headlib.h"

//int debug = 1;
// 图像格式标志枚举类型
enum matrixenum
{
    RGB,
    GRAY,
    CMYK,
    BGR,
    YCC,
    HSV,
    Lab,
};
struct matrix {
    int h;
    int w;
    char channel;
	char mode;  // 标记图像格式
    int sum;
    uchar* data;
    void* d;
};        // matrix struct 矩阵结构体

#define PPM_P6_OUT  1
#define RAW_OUT 2
#define OK 0
#define FALSE 1
#define PROCESS_OK 0
#define PROCESS_FALSE 1
#define clip(a,b,c) ((a)<(b)?(b):(a)>(c)?(c):(a))
#define intmax(a,b) ((a)>(b)?(a):(b))

enum PROCESSFILTERENUM
{
    BILATERALFILTER = 1,        //bilatera
    SOBELFILTER = 2,            //sobel
    SOBELFILTER_XY = 3,         //sobel xy
    SOBELBILATERAL = 4,         //mix sobel and bilateral
    CANNY=5,                    //my canny 算法
    NONMAXDOUBLETHRE,           //Do 'Bilatera' after 'DoubleThre'，非极大值抑制双边滤波
    GRADIENT_9X9,
    GRADIENT_7X7,
    GRADIENT_3X3,
    GRADIENT_AVG_3X3,
    GRADIENT_AVG_7X7,
    LINE_DETECT,

};

struct imginfo {            //image information
    char* inpath;
    char* savepath;
    int w;
    int h;
    char c;
};

struct cannypara {
    int dt[2];                  //double thresholding
    int atl;                    //angle table length
    int* at;                    //angle table
};

struct para {
    char mode;
    imginfo img;
    matrix gaustable;
    cannypara cny;
};

matrix readMat(imginfo imgif);
void writeMat(matrix outdata, const char* savepath, uchar wflag);
para parseconfig(const char* inparapath);

char gaussionfilter(matrix inmat, matrix outmat, matrix table);

void ppm2tif();
//inline int GetRGB2YCC_Y(int r,int g,int b);
//inline int GetRGB2YCC_Cb(int r, int g, int b);
//inline int GetRGB2YCC_Cr(int r, int g, int b);
//inline int GetYCC2RGB_R(int y, int cb, int cr);
//inline int GetYCC2RGB_G(int y, int cb, int cr);
//inline int GetYCC2RGB_B(int y, int cb, int cr);
char RGB2YCC(int r, int g, int b, int& y, int& cb, int& cr);
char YCC2RGB(int y, int cb, int cr, int& r, int& g, int& b);
void addimgs(matrix srcimg, matrix edgemap, matrix outimg);

uchar* GetGrayimg0(matrix img);

void SetGammaTable(uchar* table, int length, double gamma);

#endif //UTILS_H